import React from 'react';
import { Card } from 'antd';
import {browserHistory} from 'react-router';
import TableView from './../TableView';

export default class feedbackList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            findFeedbacks: GLOBAL.baseURL + "/webAPI/feedback/findFeedbacks",
            totalPageNum: 0,
            ServiceData: [],
            searchObject: {
              beforeOfAfter: "after"
            }
        }
    }
    totalPageNum(num) {
        this.setState({
            totalPageNum: num
        })
    }
    getServiceData(data) {
        this.setState({
            ServiceData: data
        });
    }
    routerParentsDetail(id){
      browserHistory.push("/backstage/feedbackList/feedbackDetail/" + id);
    }
    renderItem(item, index) {
        item.commitTime = new Date(item.commitTime).Format('yyyy-MM-dd hh:mm:ss');
        return (
            <Card key={index} onClick={this.routerParentsDetail.bind(this, item.id)} className="divItemLine" style={{minWidth: "351px"}}>
                <div className="divUserHead">
                  <img className="imgFeedback" style={{borderRadius: '50%'}} src="/src/styles/images/default.png"/>
                </div>
                <div className="userInfo">
                    <div className="divFeekbookContent" title={((item.content == undefined)?"":item.content)}>
                        <span>{((item.content == undefined)?"":item.content)}</span>
                    </div>
                    <div style={{textAlign: 'right', width: '224px'}}>
                        <span>{((item.commitTime == undefined)?"":item.commitTime)}</span>
                    </div>
                </div>
            </Card>
        );
    }
    render() {
        if(this.props.params.id == undefined){
            var serverList = null;
            if(this.state.ServiceData.length != 0){
                serverList = <div style={{marginBottom: '20px'}}>
                  {
                      this.state.ServiceData.map((item, index) => {
                          return this.renderItem(item, index);
                      })
                  }
                </div>
            }else{
                serverList = <div className="divEmptyData">对不起，没有相关数据。</div>
            }
            return (
              <div>
                  {serverList}
                  <TableView ref="tableView" totalPageNum={this.totalPageNum.bind(this)}
                             isInternalRendering={false} getServiceData={this.getServiceData.bind(this)}
                             isService={true} searchObject={this.state.searchObject} pageNum={10}
                             url={this.state.findFeedbacks} method="post"/>
              </div>
            )
        }else{
            return(this.props.children)
        }
    }
}
